﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data.OleDb;
using System.Data;

namespace Web_HengliSeed.BLL
{
    public class JobInfo
    {
        /// <summary>
        ///获取一条资讯信息
        /// </summary>
        /// <param name="strProID"></param>
        /// <returns></returns>
        public static OleDbDataReader GetJobnfo(string strJobID)
        {
            try
            {
                OleDbParameter[] parm = { new OleDbParameter("@T_JobID", strJobID) };
                return ClassFile.AccessHelper.ExecuteReader(ClassFile.AccessHelper.ConnectionString, " SELECT * FROM T_Job WHERE T_JobID=@T_JobID ", parm);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        /// <summary>
        /// 删除指定ID的资讯
        /// </summary>
        /// <param name="strProClass"></param>
        /// <returns></returns>
        public static bool DelJobInfo(string strProID)
        {
            try
            {
                string strSql = string.Format(" DELETE FROM T_Job WHERE T_JobID in({0}) ", strProID);
                return (ClassFile.AccessHelper.ExecuteNonQuery(ClassFile.AccessHelper.ConnectionString, strSql, null) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 编辑资讯数据（更新）
        /// </summary>
        /// <param name="ClassID"></param>
        /// <param name="strClassName"></param>
        /// <param name="strKey"></param>
        /// <param name="strDes"></param>
        /// <returns></returns>
        public static bool EditJobMes(string strT_ProductID, string strT_ProductName, string strT_ProClassID, string strT_ProductNote, string lan)
        {
            try
            {
                string strSql = " INSERT INTO  T_NewsInfo (T_NewsTitle,T_NewsClassID,T_NewsNote,T_DateTime,T_Language) VALUES (@T_NewsTitle,@T_NewsClassID,@T_NewsNote,@T_DateTime,@T_Language) ";
                if (!string.IsNullOrEmpty(strT_ProductID))
                {
                    strSql = "UPDATE  T_NewsInfo SET T_NewsTitle=@T_NewsTitle,T_NewsClassID=@T_NewsClassID,T_NewsNote=@T_NewsNote,T_DateTime=@T_DateTime WHERE  T_NewsID=@T_NewsID ";
                }
                OleDbParameter[] parm = { new OleDbParameter("@T_NewsTitle", strT_ProductName),
                                                           new OleDbParameter("@T_NewsClassID", strT_ProClassID),
                                                           new OleDbParameter("@T_NewsNote", strT_ProductNote),
                                                           new OleDbParameter("@T_DateTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")),
                                                           new OleDbParameter("@T_NewsID", strT_ProductID),
                                                            new OleDbParameter("@T_Language", lan)};
                return (ClassFile.AccessHelper.ExecuteNonQuery(ClassFile.AccessHelper.ConnectionString, strSql, parm) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 分页查询资讯信息
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageCount"></param>
        /// <returns></returns>
        public static DataTable GetAllNewsInfo(int PageIndex, int PageSize, out int PageCount, out int RecordCount, string strWhere, string lan)
        {
            try
            {
                //if (string.IsNullOrEmpty(strWhere))
                //    strWhere += " where T_Language='" + lan + "'";
                //else
                //    strWhere += " and T_Language='" + lan + "'";

                string strSql = " SELECT P.T_NewsID,P.T_NewsClassID,P.T_NewsTitle,P.T_DateTime,C.T_NewsClassName,C.T_NewsClassKey,C.T_NewsClassDes FROM T_NewsInfo P  " +
                                " LEFT JOIN T_NewsClass C ON P.T_NewsClassID=C.T_NewsClassID WHERE C.T_Language='" + lan + "' ";
                string strShow = " T_NewsID,T_NewsTitle,T_NewsClassName,T_DateTime,T_NewsClassKey,T_NewsClassDes ";
                return ClassFile.AccessHelper.ExecutePager(PageIndex, PageSize, "T_NewsID", strShow, strSql, strWhere, " T_NewsID DESC ", out PageCount, out RecordCount);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

    }
}